package com.xiaobai.controller;

import io.jsonwebtoken.Jwts;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;

/**
 * @author yangdaji
 * @version 1.0
 * @Description: 验证user
 * @date 22-2-19 上午 2:09
 */
@RestController
@RequestMapping("/user")
public class UserController {


    /**
     * 获取用户信息
     *
     * @param authentication
     * @return
     */
    @RequestMapping("/get")
    public Object getUser(Authentication authentication, HttpServletRequest request) {

        String bb = request.getHeader("Authorization");
        String bearer = bb.substring(bb.indexOf("Bearer") + 7);
        return Jwts.parser()
                //设置密钥
                .setSigningKey("test_key".getBytes(StandardCharsets.UTF_8))
                //解析token
                .parseClaimsJws(bearer).getBody();
        /**
         * 后续做认证登录时可以前端调用获取token接口返回对应token信息
         *
         */
    }
    /**
     * 单点登录,client登录进行授权认证从而获取资源服务的资源
     */
}
